<?php


function get_index(){
	$str = <<<INDEX
	<?php
	foreach(glob("../app/*.class.php") as \$file){
		require_once(\$file);
	}
	\$httppath = Config::getHTTPPath();
	\$httppath_array = array_filter(explode("/", \$httppath));

	// The path user is requesting
	\$path = \$_SERVER['REQUEST_URI'];
	\$path_array = array_filter(explode("/", \$path));
	\$final = array_diff_assoc(\$path_array, \$httppath_array);
	\$final = array_filter(\$final);

	// Get the first two elements
	\$i=1;
	foreach(\$final as \$element){
		if(\$i == 1) { 
			\$controller = \$element;
		}
		if(\$i == 2) {
			\$action = \$element;
		}
		\$i++;
	}

	\$controller = array_shift(\$final);
	\$action = array_shift(\$final);


	if(!isset(\$controller)) { \$controller="root"; }
	if(!isset(\$action)){ \$action = "index"; }

	\$object = ucfirst(\$controller)."_Controller";
	if(class_exists(\$object)){	
		\$control = new \$object(\$final);
		if(method_exists(\$control, \$action)){
			\$control->{\$action}(\$final);
			exit();	
		}else{
			\$control = new Error_Controller;
			\$control->index();
			exit();
		}
	} else {
		\$control = new Error_Controller;
		\$control->index();
		exit();
	}
	?>
INDEX;
	return $str;
}
?>
